#include "utils.h"
#include "error_cg.h"
#include "program_cg.h"

namespace venus {
ProgramCG::ProgramCG(CGcontext context, const char *filename, 
                     const char *entry, CGGLenum profile_class) {
  profile_ = cgGLGetLatestProfile(profile_class);
  program_ = cgCreateProgramFromFile(context, CG_SOURCE, filename, 
                                     profile_, entry, 0);
  if (0 == program_) {
    Error("failed to create program from %s", filename);
  } else {
    cgGLLoadProgram(program_);
  }
  CheckErrorCG("ProgramCG");
}
ProgramCG::~ProgramCG() {
  cgDestroyProgram(program_);
}
int ProgramCG::Activate() const {
  cgGLBindProgram(program_);
  cgGLEnableProfile(profile_);
  if(CheckErrorCG("Activate")) return -1;
  return 0;
}
void ProgramCG::Deactivate() const {
  cgGLDisableProfile(profile_);
}
} // namespace venus
